package com.systemframework.sys.controller;

import com.systemframework.annotation.LicenseAnnotation;
import com.systemframework.sys.dto.request.SysMenuRequestDTO;
import com.systemframework.sys.dto.response.SysMenuResponseDTO;
import com.systemframework.sys.dto.response.SysRoleMenuResponseDTO;
import com.systemframework.sys.service.SysMenuService;
import com.systemframework.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author summer
 * @date 2023-03-10 14:32
 */
@RestController
@RequestMapping(value = "/menu")
public class SysMenuController {

    private SysMenuService sysMenuService;

    @Autowired
    public void setSysMenuService(SysMenuService sysMenuService) {
        this.sysMenuService = sysMenuService;
    }

    @LicenseAnnotation
    @GetMapping(value = "/lists/{pId}")
    public Result<List<SysMenuResponseDTO>> lists(@PathVariable Integer pId){
       return Result.successResult(sysMenuService.lists(pId));
    }

    @LicenseAnnotation
    @GetMapping(value = "/menuLists/{roleId}")
    public Result<SysRoleMenuResponseDTO> menuLists(@PathVariable Integer roleId){
        return Result.successResult(sysMenuService.menuLists(roleId));
    }

    @LicenseAnnotation
    @GetMapping(value = "/menus")
    public Result<List<SysMenuResponseDTO>> menus(){
        return Result.successResult(sysMenuService.menus());
    }

    @LicenseAnnotation
    @PostMapping(value = "/save")
    public Result<String>  save(@Valid @RequestBody SysMenuRequestDTO sysMenuRequestDTO){
        sysMenuService.saveMenu(sysMenuRequestDTO);
        return Result.successResult();
    }
}
